package run.bottle.app.service;

import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import run.bottle.app.exception.NotFoundException;
import run.bottle.app.model.entity.SysUser;
import run.bottle.app.service.base.CrudService;

import java.util.Optional;

/**
 * User service interface.
 *
 * @author Lycheng
 */
public interface UserService extends CrudService<SysUser, Integer> {

    /**
     * 通过用户名获取用户
     *
     * @param username username must not be blank
     * @return an optional user
     */
    @NonNull
    Optional<SysUser> getByUsername(@NonNull String username);

    /**
     * 通过用户名获取非null用户
     *
     * @param username username
     * @return user info
     * @throws NotFoundException throws when the username does not exist
     */
    @NonNull
    SysUser getByUsernameOfNonNull(@NonNull String username);

    /**
     * 通过电子邮件获取用户
     *
     * @param email email must not be blank
     * @return an optional user
     */
    @NonNull
    Optional<SysUser> getByEmail(@NonNull String email);

    /**
     * 通过电子邮件获取非null用户
     *
     * @param email email
     * @return user info
     * @throws NotFoundException throws when the username does not exist
     */
    @NonNull
    SysUser getByEmailOfNonNull(@NonNull String email);

    /**
     * 检查密码是否与用户密码匹配
     *
     * @param user          user info must not be null
     * @param plainPassword plain password
     * @return true if the given password is match the user password; false otherwise
     */
    boolean passwordMatch(@NonNull SysUser user, @Nullable String plainPassword);


}
